#!/bin/sh


PROJECT_DIR=$(dirname $0)
cd $PROJECT_DIR; PROJECT_DIR=`pwd`; cd - > /dev/null
PROJECT_NAME=`basename $PROJECT_DIR`

rm -rf ~/.sinan
cd $PROJECT_DIR
rm -rf $PROJECT_NAME-*
sinan clean
sinan 
sinan release
cd -

VSN=$(basename $(dirname $(ls $PROJECT_DIR/_build/development/releases/*/$PROJECT_NAME".boot" 2> /dev/null | sed s/.boot// 2> /dev/null)))
RELEASE_NAME=$PROJECT_NAME"-"$VSN
RELEASE_DIR=$PROJECT_DIR"/"$RELEASE_NAME
echo "PROJECT_DIR $PROJECT_DIR"
echo "PROJECT_NAME $PROJECT_NAME"
echo "VSN $VSN"
echo "RELEASE_DIR $RELEASE_DIR"


echo "making release for $RELEASE_NAME"

cd $PROJECT_DIR; 
mkdir $RELEASE_DIR
cp -r _build/development/releases $RELEASE_DIR
cp -r cmds $RELEASE_DIR
rm -f $RELEASE_DIR/bin/$PROJECT_NAME"_dev"
cp -r ~/.sinan/repo $RELEASE_DIR/lib
cp -r _build/development/apps/*-* $RELEASE_DIR/lib
cp LICENCE README install.sh $RELEASE_DIR
find $RELEASE_DIR -name ".svn" | xargs rm -rf 
find $RELEASE_DIR -name "*~*" | xargs rm -rf 
tar -zcf $RELEASE_NAME.tar.gz $RELEASE_NAME; 
cd -


